package view.panel
{
	import control.panel.AddFriendPanelControl;
	import control.panel.IPanelControl;
	
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import model.role.IRoleData;
	
	import utils.TextTool;
	
	import view.LabelText;
	import view.components.ImgButton;
	import view.components.NumericStepper;
	import view.components.RemoteHtmlImg;
	
	import global.GameState;
	
	public class AddFriendPanel extends AbsPanel
	{
		private var presentBut:ImgButton;
		private var addBut:ImgButton;
		private var homeBut:ImgButton;
		private var giveBut:ImgButton;
		
		private var remoteImg:RemoteHtmlImg;
		
		private var nameText:TextField;
		private var moneyText:TextField;
		private var homeText:TextField;
		private var hintText:TextField;
		
		private var roleData:IRoleData;
		private var numericStepper:NumericStepper;
		

		
		public function AddFriendPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			
			resetBg(263,166);
			initCloseBut();
			resetCloseBut();
			setTableCenter();
			dropShadow();
			initTweenPanelOpen();
			
			initButs();
			initRemoteImg();
			initText();
			initNumericStepper();			
		}
		
		private function initNumericStepper():void
		{
			numericStepper = new NumericStepper();
			numericStepper.x = 123;
			numericStepper.y = 80;
			numericStepper.width = 100;
			numericStepper.height = 20;
			addChild(numericStepper);
		}
		
		private function initText():void
		{
			nameText = TextTool.getTextFieldXY(110,16,100,20,14,0xFFFFFF,"",false,true);
			addChild(nameText);
			
			moneyText = TextTool.getTextFieldXY(110,36,100,20,12,0xFFFF00,"");
			addChild(moneyText);
			
			homeText = TextTool.getTextFieldXY(110,56,100,20,12,0xFFFFFF,"");
			addChild(homeText);
			
			hintText = TextTool.getTextFieldXY(110,130,140,40,12,0xFFFFFF,"",false,false,"center");
			hintText.multiline = true;
			hintText.wordWrap = true;
			addChild(hintText);
		}
		
		private function initRemoteImg():void
		{
			remoteImg = new RemoteHtmlImg(50,50);
			remoteImg.mouseEnabled = false;
			remoteImg.x = 28;
			remoteImg.y = 16;
			addChild(remoteImg);
		}
		
		private function initButs():void
		{
			presentBut =  new ImgButton(20,78,0,onBut,79,22,"butBg",null,"赠送道具",12,0xFFFFFF,false);
			addBut =      new ImgButton(20,102,1,onBut,79,22,"butBg",null,"加为牌友",12,0xFFFFFF,false);
			if (GameState.sns != "2")
			{
				homeBut =     new ImgButton(20,126,2,onBut,79,22,"butBg",null,"个人主页",12,0xFFFFFF,false);
				addChild(homeBut);
			}
			giveBut = new ImgButton(114,100,3,onBut,120,32,"butBg2",null,"赠送金币",12,0xFFFFFF,false);
			
			addChild(presentBut);
		
			//homeBut.mouseEnabled = false;
			//giveBut.mouseEnabled = false;
			
			addChild(addBut);
			
			addChild(giveBut);
		}
		
		public function update(roleData:IRoleData):void
		{
			this.roleData = roleData;
			nameText.text = roleData.roleName;
			moneyText.text = "$" +  roleData.money;
			homeText.text = "来自:" + roleData.snsName;
			
			remoteImg.loadImg(roleData.imgUrl);
			
			numericStepper.maximum = GameState.gameRoomFee;
			numericStepper.minimun = Math.floor(GameState.gameRoomFee * .1);
			numericStepper.value = Math.floor(GameState.gameRoomFee * .1);
			numericStepper.stepSize = Math.floor(GameState.gameRoomFee * .1);
			
			hintText.text = "本房间最多赠送:\n" + GameState.gameRoomFee + "金币";
		}
		
		private function onBut(event:MouseEvent):void
		{
			switch (event.target.id)
			{
				case 0://赠送道具
					(panelControl as AddFriendPanelControl).onPresent();
					break;
				case 1:
					(panelControl as AddFriendPanelControl).onAddFriendApply(roleData.sitId);
					break;
				case 2:
					(panelControl as AddFriendPanelControl).goHomePage();
					break;
				case 3:
					(panelControl as AddFriendPanelControl).sendPresentMoney(numericStepper.value);
					break;
			}
		}
	}
}